//
//  WKCommentCell.m
//  WKDemo
//
//  Created by apple on 14-8-10.
//  Copyright (c) 2014年 com.app. All rights reserved.
//

#import "WKCommentCell.h"
#import "UIImage+MJ.h"
#import "WKCommentResult.h"

@interface WKCommentCell ()
@property (nonatomic, weak) UIImageView *iconView;
@property (nonatomic, weak) UILabel *nameLabel;
@property (nonatomic, weak) UIImageView *sexView;
@property (nonatomic, weak) UILabel *content;
@end
@implementation WKCommentCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        UIImageView *icon = [[UIImageView alloc] init];
        [self addSubview:icon];
        self.iconView = icon;
        
        UILabel *nameL = [[UILabel alloc] init];
        nameL.font = [UIFont systemFontOfSize:11.0];
        nameL.contentMode = UIViewContentModeTop;
        [self addSubview:nameL];
        self.nameLabel = nameL;
        
        UIImageView *sex = [[UIImageView alloc] init];
        [self addSubview:sex];
        self.sexView = sex;
        
        UILabel *content = [[UILabel alloc] init];
        content.font = [UIFont systemFontOfSize:11.0];
        content.numberOfLines = 0;
        [self addSubview:content];
        self.content = content;
    }
    return self;
}
- (void)setCommentR:(WKCommentResult *)commentR
{
    _commentR = commentR;
    
    CGFloat magrin  = 5;
    CGFloat iconX = magrin;
    CGFloat iconY = magrin;
    CGFloat iconW = 30;
    CGFloat iconH = 30;
    self.iconView.frame = CGRectMake(iconX, iconY, iconW, iconH);
    [self.iconView setImageWithURL:[NSURL URLWithString:commentR.profile_image]];
    
    CGFloat sexX = CGRectGetMaxX(self.iconView.frame)+magrin;
    CGFloat sexY = magrin;
    CGFloat sexW = 10;
    CGFloat sexH = 10;
    self.sexView.frame = CGRectMake(sexX, sexY, sexW, sexH);
    if ([commentR.sex isEqualToString:@"m"]) {
        self.sexView.image = [UIImage imageNamed:@"nan"];
    }else
    {
        self.sexView.image = [UIImage imageNamed:@"nv"];
    }
    
    CGFloat nameX = CGRectGetMaxX(self.sexView.frame)+magrin;
    CGFloat nameY = magrin;
    CGSize namesize = [commentR.username sizeWithFont:[UIFont systemFontOfSize:11.0]];
    CGFloat nameW = namesize.width;
    CGFloat nameH = namesize.height;
    self.nameLabel.frame = CGRectMake(nameX, nameY, nameW, nameH);
    self.nameLabel.text = commentR.username;
    
    CGFloat contentX = self.sexView.frame.origin.x;
    CGFloat contentY = CGRectGetMaxY(self.nameLabel.frame)+magrin;
    CGSize size = [commentR.content sizeWithFont:[UIFont systemFontOfSize:11.0]];
    CGFloat contentW = size.width;
    CGFloat contentH = size.height;
    self.content.text = commentR.content;
    self.content.frame = CGRectMake(contentX, contentY, contentW, contentH);

}
+ (instancetype)cellWithTableView:(UITableView *)tableView
{
static NSString *ID = @"comment";
    WKCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (cell== nil) {
        cell = [[WKCommentCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];
    }
    return cell;
}
@end
